import { Module } from '@nestjs/common';
import { UserModule } from './module/user/user.module';
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
import DATABASE_CONFIG from './config/database';
import { MailerModule } from '@nestjs-modules/mailer';
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';
import { RoleModule } from './module/role/role.module';
import { PermissionModule } from './module/permission/permission.module';
import { UploadModule } from './module/upload/upload.module';
import { ArticleModule } from './module/article/article.module';
import { TagModule } from './module/tag/tag.module';
import { BrandModule } from './module/brand/brand.module';
import { InventoryHistoryModule } from './module/inventory-history/inventory-history.module';

@Module({
  imports: [
    TypeOrmModule.forRoot(DATABASE_CONFIG as TypeOrmModuleOptions),
    UserModule,
    MailerModule.forRoot({
      transport: {
        host: 'smtp.qq.com',
        port: 465,
        secure: true, // true for 465, false for other ports
        auth: {
          user: '2020974511@qq.com', // generated ethereal user
          pass: 'uletcmvflevgcbjc', // generated ethereal password
        },
      },
      defaults: {
        from: '"2020974511@qq.com', // outgoing email ID
      },
      template: {
        dir: process.cwd() + '/src/template/',
        adapter: new HandlebarsAdapter(),
        options: {
          strict: true,
        },
      },
    }),
    RoleModule,
    PermissionModule,
    UploadModule,
    ArticleModule,
    TagModule,
    BrandModule,
    InventoryHistoryModule,
  ],
})
export class AppModule {}
